<?php

require ("sharedResources.php");

$sid = '';
try {
	// We need a SID (session ID) in order to operate
	$sid = login ( 'admin', 'admin' );
	echo 'sid: ' . $sid . PHP_EOL;
	

	// Requested parameters 
	// (although they are not evaluated during document creation)
	$doc ['creatorId'] = 0;
	$doc ['dateCategory'] = 0;
	$doc ['docType'] = 0;
	$doc ['exportStatus'] = 0;
	$doc ['fileSize'] = 0;
	$doc ['id'] = 0;
	$doc ['immutable'] = 0;
	$doc ['indexed'] = 0;
	$doc ['lengthCategory'] = 0;
	$doc ['publisherId'] = 0;
	$doc ['signed'] = 0;
	$doc ['size'] = 0;
	$doc ['status'] = 0; // Status = 0: document unlocked
	
	// Setting some useful Tags for the document created (tags must be separated by commas)
	$doc ['tags'] = array('logicaldoc', 'installation', 'guide', 'manual');
	
	// This is new in 6.4	
	$doc ['published'] = 1;	
	
	// read the binary content of a file
	$myFile = "2013-281-out.pdf";
	$myFilePath = "C:\\tmp\\" . $myFile;
	$fh = fopen ( $myFilePath, 'r' );
	$theData = fread ( $fh, filesize ( $myFilePath ) );
	fclose ( $fh );
	//echo $theData;
	
	
    $doc ['language'] = 'it'; // This is important for indexing/search
	$doc ['fileName'] = $myFile;
	$doc ['folderId'] = DEFAULT_WORKSPACE; // create the document in DEFAULT_WORKSPACE	

	$content = $theData; // bytes?? or base64 encoded value? Don't Know BUT IT wORKS!
	
	
	$createParams = array ('sid' => $sid, 'document' => $doc, 'content' => $content );
	
	$result = $documentClient->create ( $createParams );
	print_r ( $result );
	
	echo PHP_EOL . 'Document created with Title: ' . $result->document->title . '; ID: ' . $result->document->id;
	echo PHP_EOL . 'Document fileName: ' . $result->document->fileName . '; size: ' . $result->document->fileSize;
	echo PHP_EOL . 'Document date: ' . $result->document->date;
	//unset ( $documentClient );
} catch ( SoapFault $e ) {
	print_r ( $e );
} 

// Always we need to logout in order to release connection slot
logout ( $sid );
?> 
	